<?php

class ContactController extends Controller {

    public function actions() {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    public function actionIndex() {
        $model = new ContactForm;
        if (isset($_POST['ContactForm'])) {
            $model->attributes = $_POST['ContactForm'];
            if ($model->validate()) {
                //$headers="From: {$model->email}\r\nReply-To: {$model->email}";
                //mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
                Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
                $question = new question();
                $question->first_name = $model->name;
                $question->last_name = $model->last_name;
                $question->message = $model->body;
                $question->email = $model->email;
                $question->date = date('Y-m-d');
                $question->save();

                $this->refresh();
            }
        }
        $this->render('contact', array('model' => $model));
    }

    public function actionList() {
        $question = question::model()->findAll();
        $this->render('list', array('question' => $question));
    }

}